import baseservice from '../common/baseservice.js';
export default {
	getPageData(self, successBack, errorBack) {
		baseservice.getPageData(self, self.apis.projectPage, self.searchcondition, successBack, errorBack);
	},
	getModelData(self, id, successBack, errorBack) {
		baseservice.getModelData(self, self.apis.projectGet, id, function(res) {
			if(res.data) {
				self.modelData = res.data;
				if(self.modelData != null && self.modelData.id > 0) {
					if(self.modelData.careerTags) {
						self.selectedjobs = self.modelData.careerTags.split(',');
					}
					if(self.modelData.tags) {
						self.selectedtags = self.modelData.tags.split(',');
					}
					if(self.modelData.bpAttactId) {
						self.fileList.push({
							name: self.modelData.bpAttactName
						});
					}
				}
			}
		});
	},
	showDetail(self, row, title) {
		baseservice.showDetail(self, row, title);
	},
	handleDelete(self, id, successBack, errorBack) {
		let that = this;
		baseservice.handleDelete(self, self.apis.projectDel, id, function(res) {
			that.getPageData(self);
		});
	},
	handleSave(self, successBack, errorBack) {
		if(self.selectedtags)
			self.modelData.tags = self.selectedtags.join(',');
		if(self.selectedjobs)	
			self.modelData.careerTags = self.selectedjobs.join(',');
		let rule = [{
			name: 'logo',
			label: '项目封面',
			rule: ['validateUpload_']
		}, {
			name: 'title',
			label: '项目标题',
			rule: ['validateEmpty_']
		}, {
			name: 'city',
			label: '城市',
			rule: ['validateEmpty_']
		}, {
			name: 'careerTags',
			label: '所属行业',
			rule: ['validateSelect_']
		}, {
			name: 'tags',
			label: '标签',
			rule: ['validateSelect_']
		}];

		if(!self.validatetool.validate(self, self.modelData, rule)) {
			return;
		}

		let requestUrl = self.apis.projectAdd;
		let msg = '添加成功';
		if(self.modelData.id > 0) {
			requestUrl = self.apis.projectUpdate;
			msg = '修改成功';
		}
		baseservice.handleSave(self, requestUrl, self.modelData, msg);
	}
}